using System;
using FluentIoC.Configuration;
using FluentIoC.Interfaces;
using FluentIoC.Windsor;

namespace FluentIoC
{
    internal class ContainerManager
    {
        private const string _defaultContainerKey = "default.environment";

        private IIoCConfiguration _configuration;

        public IContainer Container
        {
            get { return _configuration.Container; }
        }

        public ContainerManager()
        {
            _configuration = new WindsorIoCConfiguration(
                new WindsorContainer(_defaultContainerKey)
            );
        }

        public void AddConfiguration(ContainerConfiguration configuration)
        {
            configuration.Configure(_configuration);
        }

        public void AddContainers(Type[] configurations)
        {
            foreach(var config in configurations)
            {
                var container = Activator.CreateInstance(config) as ContainerConfiguration;

                if(null != container)
                {
                    AddConfiguration(container);
                }
            }
        }
    }
}